package ModelLayer;
import java.util.HashMap;
import java.util.Iterator;

public class ProductList
{
    private HashMap<Integer,Product> products;
    private static ProductList instance=null;
    
    private ProductList()
    {
        products = new HashMap<>();
        
        addProduct(new Product(996, "Paint", "Pure Brilliant White 25L", 699.99, "DIY",148));
        addProduct(new Product(997, "Paint", "Apple mist 15L", 499.98, "DIY",300));
        addProduct(new Product(998, "Screws", "Hex cap 3 inches pack of 50", 49.97 , "DIY",358));
        addProduct(new Product(999, "Wood", "Oak wood 200x60 cm", 120.85, "TIMBER",50));
    }
    
    public static ProductList getInstance()
    {
        if(instance==null)
        {
            instance = new ProductList();
        }
        
        return instance;
    }
    
    public void addProduct(Product product)
    {
        products.put((Integer)product.getId(),product);
    }
    
    public Product getProduct(int id)
    {
        if(products.containsKey((Integer)id))   return products.get(id);
        
        return null;
    }
    
    public boolean removeProduct(int id)
    {
        return (products.remove(id)!=null);
    }
    
    public Iterator getProductsIterator() { return products.values().iterator(); }
    public int getProductsSize() { return products.size(); }
}